
<template>
  <div class="dashboard-view">
    <h1>后台管理面板</h1>
    <p>这里是系统的数据概览和核心指标。</p>

    <el-row :gutter="20" class="stats-cards">
      <el-col :span="6">
        <el-card class="stat-card">
          <el-statistic title="总用户数" :value="stats.userCount">
            <template #prefix>
              <el-icon><User /></el-icon>
            </template>
          </el-statistic>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <el-statistic title="总订单数" :value="stats.orderCount">
            <template #prefix>
              <el-icon><Document /></el-icon>
            </template>
          </el-statistic>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <el-statistic title="待处理订单" :value="stats.pendingOrderCount">
            <template #prefix>
              <el-icon><Clock /></el-icon>
            </template>
          </el-statistic>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <el-statistic title="总消耗积分" :value="stats.totalPointsSpent">
            <template #prefix>
              <el-icon><Star /></el-icon>
            </template>
          </el-statistic>
        </el-card>
      </el-col>
    </el-row>

  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { User, Document, Clock, Star } from '@element-plus/icons-vue'
import type { DashboardStats } from '@/types'
import { getDashboardStats } from '@/api/modules/dashboard'

const stats = ref<DashboardStats>({
  userCount: 0,
  orderCount: 0,
  pendingOrderCount: 0,
  totalPointsSpent: 0,
})
const loading = ref(false)

const fetchStats = async () => {
  try {
    loading.value = true
    stats.value = await getDashboardStats()
  } catch (error) {
    ElMessage.error('获取统计数据失败')
    console.error(error)
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchStats()
})
</script>

<style scoped>
.dashboard-view {
  padding: 20px;
}
.stats-cards {
  margin-top: 20px;
}
.stat-card {
  text-align: center;
}
.el-icon {
  font-size: 24px;
  margin-right: 10px;
}
</style>
